MAXM = 20
MAXN = 10
n, m = map(int, input().split())
x = [0 for _ in range(MAXM)]
used = [False for _ in range(MAXN)]


def dfs(i):
    if i > m:
        print(x[1:m + 1])
    else:
        for j in range(1, n + 1):
            if not used[j]:
                used[j] = True
                x[i] = j
                dfs(i + 1)
                used[j] = False


dfs(1)
